home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / tex-k / tex-k-archive.past / tex-k-archive.gz / tex-k-archive / 000046_fj@iesd.auc.dk_Tue Oct 12 15:54:44 1993.msg < prev    next >
Internet Message Format  |  1994-10-11  |  6KB

  1. Received: from iesd.auc.dk by cs.umb.edu with SMTP id AA26621
  2.   (5.65c/IDA-1.4.4 for <tex-k@cs.umb.edu>); Tue, 12 Oct 1993 09:55:19 -0400
  3. Received: from loke.iesd.auc.dk by iesd.auc.dk with SMTP id AA24168
  4.   (5.65c8/IDA-1.5/MD for <tex-k@cs.umb.edu>); Tue, 12 Oct 1993 14:53:32 +0100
  5. Received: by loke.iesd.auc.dk id AA16877
  6.   (5.65c8/IDA-CLIENT/MD); Tue, 12 Oct 1993 14:54:44 +0100
  7. Date: Tue, 12 Oct 1993 14:54:44 +0100
  8. From: Frank Jensen <fj@iesd.auc.dk>
  9. Message-Id: <199310121354.AA16877@loke.iesd.auc.dk>
  10. To: tex-k@cs.umb.edu
  11. Subject: Speed of (recursive) search in the Kpathsearch library
  12.  
  13.  
  14. I'm sure most people have noticed the delay due to the recursive
  15. search of subdirectories when TeX starts up.  [Our users certainly
  16. have as they have started to make private copies of the style files
  17. they need and abandon the search of the `global' style directories.]
  18.  
  19. At our site, we have in the TeX `inputs' directory approximately 1500
  20. files distributed in 75 directories (and only very few of the ordinary
  21. files are located in non-leaf directories).  And this hierarchy is
  22. getting larger, not smaller.  This takes a noticable amount of time to
  23. search despite the clever trick Karl uses to speed it up.
  24.  
  25. So I tried to see how much I could speed up the search by having a
  26. precompiled list of all input files available in a directory
  27. hierarchy.  I assumed this list to be a simple text file in the format
  28. produced by the (GNU) `ls' command with option `-R', and that the file
  29. would be located at the root of the hierarchy and named "ls-R".  And
  30. IMO, the results are promising: the start up + search is (for all
  31. practical purposes) instantaneous.
  32.  
  33. I only modified two files: `pathsearch.c' and `elt-dirs.c'.  [I have
  34. appended diffs for the changes below.  I can of course supply complete
  35. copies of the files, if needed.]  I only made the absolute minimum of
  36. changes to make it work.  It hasn't been tuned: for example, the
  37. "ls-R" file is read every time, we search for a file; it should only
  38. be read the first time.
  39.  
  40. Anyway, I think something like this is worthwhile despite the need to
  41. maintain an extra file.  What do you think?
  42.  
  43. ---
  44. Frank Jensen,   fj@iesd.auc.dk
  45. Department of Mathematics and Computer Science
  46. Aalborg University
  47. DENMARK
  48.  
  49.  
  50. *** pathsearch.c    Sat Sep 25 20:13:28 1993
  51. --- pathsearch.c.new    Mon Oct 11 19:03:22 1993
  52. ***************
  53. *** 18,23 ****
  54. --- 18,26 ----
  55.   
  56.   #include <kpathsea/config.h>
  57.   
  58. + #include <kpathsea/c-fopen.h>
  59. + #include <kpathsea/line.h>
  60. + #include <kpathsea/c-pathch.h>
  61.   #include <kpathsea/absolute.h>
  62.   #include <kpathsea/expand.h>
  63.   #include <kpathsea/pathsearch.h>
  64. ***************
  65. *** 58,76 ****
  66.             XRETALLOC (potential, allocated, char);
  67.           }
  68.         
  69. !       strcpy (potential, dir);
  70. !       strcat (potential, name);
  71.         
  72. !       if (kpse_readable_file (potential))
  73. !         { /* Found a file.  Maybe one is all the caller wants.  */
  74. !           str_list_add (&ret, potential);
  75. !           if (!search_all)
  76. !             /* No need to terminate with NULL; the caller knows.  */
  77. !             return ret;
  78. !           /* Start new filename.  */
  79. !           allocated = INIT_ALLOC;
  80. !           potential = xmalloc (allocated);
  81.           }
  82.       }
  83.     
  84. --- 61,124 ----
  85.             XRETALLOC (potential, allocated, char);
  86.           }
  87.         
  88. !       if (IS_DIR_SEP (dir[dir_len - 2]))
  89. !         { /* search "ls-R" file */
  90. !       char file_name[1000]; /* arbitrary length */
  91. !       string p = file_name + dir_len - 1, q = p;
  92. !       FILE *ls_R_file;
  93. !       char *l;
  94. !       strcpy (file_name, dir);
  95. !       strcpy (p, "ls-R");
  96. !       ls_R_file = xfopen (file_name, FOPEN_R_MODE);
  97. !       while ((l = read_line (ls_R_file)) != NULL)
  98. !         {
  99. !           int llen = strlen (l);
  100. !           if (llen > 0)
  101. !         if (l[llen - 1] == ':')
  102. !           { /* new directory */
  103. !             l[llen - 1] = DIR_SEP;
  104. !             strcpy (p, l);
  105. !             q = p + llen;
  106. !           }            
  107. !             else if (strcmp (l, name) == 0)
  108. !           { /* we expect a file to be found now */
  109. !             strcpy (q, l);
  110. !             if (kpse_readable_file (file_name)) /* just to check */
  111. !               { /* Found a file; maybe one is all the caller wants. */
  112. !               str_list_add (&ret, xstrdup (file_name));
  113. !               if (!search_all)
  114. !                 { /* No need to terminate with NULL;
  115. !                  the caller knows. */
  116. !                   free (l);
  117. !                   strcpy (p, "ls-R");
  118. !                   xfclose (ls_R_file, file_name);
  119. !                   return ret;
  120. !                 }
  121. !               }
  122. !           }
  123. !           free (l);
  124. !         }
  125. !       strcpy (p, "ls-R");
  126. !       xfclose (ls_R_file, file_name);
  127. !     }
  128. !       else
  129. !     {
  130. !       strcpy (potential, dir);
  131. !       strcat (potential, name);
  132.         
  133. !       if (kpse_readable_file (potential))
  134. !         { /* Found a file.  Maybe one is all the caller wants.  */
  135. !           str_list_add (&ret, potential);
  136. !           if (!search_all)
  137. !         /* No need to terminate with NULL; the caller knows.  */
  138. !         return ret;
  139. !           /* Start new filename.  */
  140. !           allocated = INIT_ALLOC;
  141. !           potential = xmalloc (allocated);
  142. !         }
  143.           }
  144.       }
  145.     
  146. *** elt-dirs.c    Wed Aug  4 01:42:20 1993
  147. --- elt-dirs.c.new    Mon Oct 11 19:15:14 1993
  148. ***************
  149. *** 224,231 ****
  150.             /* If two consecutive directory separators, find subdirectories.  */
  151.             if (IS_DIR_SEP (dir[1]))
  152.               {
  153. !               do_subdir (str_list_ptr, elt, dir - elt + 1, dir + 2);
  154. !               found_special = true;
  155.               }
  156.   
  157.             /* If /?, make following component optional.  */
  158. --- 224,237 ----
  159.             /* If two consecutive directory separators, find subdirectories.  */
  160.             if (IS_DIR_SEP (dir[1]))
  161.               {
  162. !           char ls_R[1000]; /* arbitrary length */
  163. !           strncpy (ls_R, elt, dir - elt + 1);
  164. !           strcpy (ls_R + (dir - elt + 1), "ls-R");
  165. !           if (!kpse_readable_file (ls_R))
  166. !         {
  167. !           do_subdir (str_list_ptr, elt, dir - elt + 1, dir + 2);
  168. !           found_special = true;
  169. !             }
  170.               }
  171.   
  172.             /* If /?, make following component optional.  */
  173.